﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Linq;
using System.Web;
using MySQL.Db;

namespace Gollie.DataTables
{
	public class MailsSentItem
	{
		public ulong MailId { get; set; }
		public string Recipient { get; set; }
		public DateTime DateSent { get; set; }
		public string Attachment { get; set; }
		public string Subject { get; set; }
		public string Body { get; set; }
	}

	public class MailsSent : BaseBindable<MailsSentItem>
	{
		public MailsSent(DateTime from, DateTime to)
		{
			ResultSet resultSet = Database.Queries.GetMails(from, to);

			this.AddDetails(resultSet);
		}

		private void AddDetails(ResultSet resultSet)
		{
			int numRows = resultSet.Count;

			for (int i = 0; i < numRows; i++)
			{
				this.Add(new MailsSentItem()
				{
					MailId = resultSet.GetUInt64(i, "id"),
					Recipient = resultSet.GetString(i, "recipient"),
					DateSent = resultSet.GetDateTime(i, "datesent"),
					Subject = resultSet.GetString(i, "subject"),
					Attachment = resultSet.GetString(i, "attachment"),
					Body = resultSet.GetString(i, "txt")
				});
			}
		}
	}
}